﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Shop.Backstage.WebProxy;
using Shop.Backstage.Models;

namespace Shop.Backstage.Filters
{
    /// <summary>
    /// 验证管理员状态
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
    public class AdminLoginAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.IsChildAction)
            {
                return;
            }
            AdminInfo CurrAdmin = AdminState.GetAdminState();
            if (CurrAdmin == null)
            {
                filterContext.Result = new RedirectResult("~/AdminLogin");
            }
        }
    }
}
